//
//  YQTabBar.m
//  WeiboOC
//
//  Created by yang on 15/11/11.
//  Copyright © 2015年 yang. All rights reserved.
//

#import "YQTabBar.h"
@implementation YQTabBar
- (UIButton*)button
{
    if (!_button) {
        UIButton* button = [[UIButton alloc] init];
        [button setBackgroundImage:[UIImage imageNamed:@"tabbar_compose_button"] forState:UIControlStateNormal];
        [button setBackgroundImage:[UIImage imageNamed:@"tabbar_compose_button_highlighted"] forState:UIControlStateSelected];
        [button setImage:[UIImage imageNamed:@"tabbar_compose_icon_add"] forState:UIControlStateNormal];
        [button setImage:[UIImage imageNamed:@"tabbar_compose_icon_add_highlighted"] forState:UIControlStateSelected];
        [button sizeToFit];
        _button = button;
    }
    return _button;
}
- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
         [self addSubview:self.button];;
    }
    return self;
}
-(void)layoutSubviews{
    [super layoutSubviews];
    CGFloat w = self.bounds.size.width / 5;
    CGFloat h = self.bounds.size.height;
    CGRect farme = CGRectMake(0, 0, w, h);
    NSInteger index = 0;
    for (UITabBar * subview in self.subviews) {
        if ([subview isKindOfClass:NSClassFromString(@"UITabBarButton")]) {
            subview.frame = CGRectOffset(farme, index * w, 0);
            index += index == 1? 2 : 1;
        }
    }
    self.button.frame = CGRectOffset(farme, w * 2, 0);
}
@end
